#include "algorithm.h"

/* Create a gradient inside a palette. The parameters are:
 *   - palette: the palette to be modified
 *   - c1 and c2: the initial and final color
 *   - initial and final: the initial and final position in the palette */
void create_gradient(SDL_Color palette[256], SDL_Color c1, SDL_Color c2, 
		int initial, int final)
{
	double n = final - initial;

	double r_inc = (c2.r - c1.r) / n;
	double g_inc = (c2.g - c1.g) / n;
	double b_inc = (c2.b - c1.b) / n;

	double r = c1.r, g = c1.g, b = c1.b;

	int i;
	for(i=0; i<n; i++)
	{
		palette[initial+i] = (SDL_Color){ r, g, b };
		r += r_inc;
		g += g_inc;
		b += b_inc;
	}
}


// Rotate a given palette, from the initial to the final position.
// Doesn't touch the SDL palette, just the palette array.
void rotate_palette(SDL_Color palette[256], int initial, int final)
{
	int i;
	SDL_Color c = palette[initial];
	
	for(i=initial; i<=final-1; i+=1)
		palette[i] = palette[i+1];
	palette[final-1] = c;
}
